package com.jh.user.controller.model;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Range;
import com.jh.user.pojo.ThirdPayRate;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Yichuan
 * @version 1.0
 */
public class ThirdPayRateVO implements Serializable {

    private static final long serialVersionUID = 3640871795130763543L;

    public static ThirdPayRateVO transform(ThirdPayRate payRate) {
        ThirdPayRateVO vo = new ThirdPayRateVO();
        vo.setId(payRate.getId());
        vo.setBrandId(payRate.getBrandId());
        vo.setType(payRate.getType().getValue());
        vo.setRanges(payRate.getRangeList());
        return vo;
    }

    public static List<ThirdPayRateVO> transform(List<ThirdPayRate> payRateList) {
        if (payRateList == null || payRateList.isEmpty()) {
            return ImmutableList.of();
        }
        List<ThirdPayRateVO> result = Lists.newLinkedList();
        for (ThirdPayRate tpr: payRateList) {
            result.add(ThirdPayRateVO.transform(tpr));
        }
        return result;
    }

    private Long id;
    private Long brandId;
    private String type;
    private List<RangeRateModel> ranges;

    public ThirdPayRateVO() {
        super();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getBrandId() {
        return brandId;
    }

    public void setBrandId(Long brandId) {
        this.brandId = brandId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<RangeRateModel> getRanges() {
        return ranges;
    }

    public void setRanges(List<RangeRateModel> ranges) {
        this.ranges = ranges;
    }

    public static List<RangeRateModel> convertRanges(Map<Range<BigDecimal>, BigDecimal> rangeData) {
        List<RangeRateModel> result = new ArrayList<>();
        for (Map.Entry<Range<BigDecimal>, BigDecimal> entry: rangeData.entrySet()) {
            result.add(RangeRateModel.range(entry.getKey(), entry.getValue()));
        }
        return result;
    }
}
